package cn.tedu.order.tcc;

import cn.tedu.order.entity.Order;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

@LocalTCC
public interface OrderTCCAction {
    /*
    BusinessActionContext
    TCC的上下文对象，通ctx对象，在两个阶段传递业务数据

    @BusinessActionContextParameter 注解
    把数据放入上下文对象，通过上下文对象可以把数据传递到第二阶段
     */
    // Try
    @TwoPhaseBusinessAction(name = "OrderTCCAction")
    boolean prepare(
            BusinessActionContext ctx,
            @BusinessActionContextParameter(paramName = "id") Long id,
            @BusinessActionContextParameter(paramName = "userId") Long userId,
            @BusinessActionContextParameter(paramName = "productId") Long productId,
            @BusinessActionContextParameter(paramName = "count") Integer count,
            @BusinessActionContextParameter(paramName = "money") BigDecimal money);

    // Confirm
    boolean commit(BusinessActionContext ctx);

    // Cancel
    boolean rollback(BusinessActionContext ctx);
}
